package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecuritymanagement.nofilterwebsitelistmanagement;

import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.management.infosecurity.violationwebsite.management.service.NoFilterService;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandOperating;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.SubCommandHandler;
import com.zx.idc.xml.entity.NoFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import static com.zx.idc.common.attributes.SchemaFileNameAttributes.NO_FILTER_WEBSITE_LIST;

/**
 * Created by hasee on 2019/3/1.
 * 违法网站列表指令内容  11.15
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class NoFilterWebsiteListManagementImpl extends CommandOperating<NoFilter> implements SubCommandHandler {

    private String schemaPath = getSchemaFilePath(NO_FILTER_WEBSITE_LIST);

    @Autowired
    private NoFilterService noFilterService;

    /**
     * 匹配方法
     *
     * @param xmlData
     * @return
     */
    @Override
    public boolean isMatch(String xmlData) {
        NoFilter noFilter = xml2Bean(xmlData, getFirstGenericClass(), schemaPath);
        return !ObjectUtils.isEmpty(noFilter);
    }

    /**
     * 执行方法
     *
     * @param xmlData
     * @param commandModel
     * @return
     */
    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        return receiveCommand(xmlData, commandModel, schemaPath);
    }

    /**
     * 覆盖该方法执行指令
     *
     * @param noFilter     实体bean
     * @param commandModel 指令mode
     */
    @Override
    public void task(NoFilter noFilter, CommandModel commandModel) {
        noFilterService.noFilter(noFilter, commandModel);
    }
}
